﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompanyManageSystem.DLL
{
    public class PageControl : XtraUserControl
    {
        /// <summary>
        /// 上一页
        /// </summary>
        private SimpleButton btn_Prev;
        /// <summary>
        /// 下一页
        /// </summary>
        private SimpleButton btn_Next;

        public int PageCount { get; set; }
        public int PageIndex { get; set; }
        public int PageSize { get; set; }
        public int TotalCount { get; set; }

        /// <summary>
        /// 刷新事件
        /// </summary>
        public event EventHandler<EventArgs> DataRefresh;
        private IContainer components;

        public PageControl()
        {
            this.components = null;
            this.InitializeComponent();
            this.PageIndex = 1;
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PageControl));
            this.btn_Prev = new DevExpress.XtraEditors.SimpleButton();
            this.btn_Next = new DevExpress.XtraEditors.SimpleButton();
            this.SuspendLayout();
            // 
            // btn_Prev
            // 
            this.btn_Prev.Image = ((System.Drawing.Image)(resources.GetObject("btn_Prev.Image")));
            this.btn_Prev.Location = new System.Drawing.Point(48, 8);
            this.btn_Prev.Name = "btn_Prev";
            this.btn_Prev.Size = new System.Drawing.Size(29, 23);
            this.btn_Prev.TabIndex = 0;
            this.btn_Prev.MouseClick += new System.Windows.Forms.MouseEventHandler(this.simpleButton1_MouseClick);
            // 
            // btn_Next
            // 
            this.btn_Next.Image = ((System.Drawing.Image)(resources.GetObject("btn_Next.Image")));
            this.btn_Next.Location = new System.Drawing.Point(117, 8);
            this.btn_Next.Name = "btn_Next";
            this.btn_Next.Size = new System.Drawing.Size(29, 23);
            this.btn_Next.TabIndex = 1;
            this.btn_Next.MouseClick += new System.Windows.Forms.MouseEventHandler(this.btn_Next_MouseClick);
            // 
            // PageControl
            // 
            this.Controls.Add(this.btn_Next);
            this.Controls.Add(this.btn_Prev);
            this.Name = "PageControl";
            this.Size = new System.Drawing.Size(442, 39);
            this.ResumeLayout(false);

        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public void PageRefresh()
        {
            if (this.DataRefresh != null)
            {
                this.DataRefresh(this, null);
                if ((this.PageCount == this.PageIndex) || (this.PageCount == 0))
                {
                    this.btn_Next.Enabled = false;
                }
                else
                {
                    this.btn_Next.Enabled = true;
                }
            }
        }

        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (this.PageIndex > 1)
            {
                int num = this.PageIndex - 1;
                this.PageIndex = num;
                this.PageRefresh();
            }

        }

        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Next_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (this.PageIndex < this.PageCount)
            {
                int num = this.PageIndex + 1;
                this.PageIndex = num;
                this.PageRefresh();
            }
        }

    }
}
